#include "features_def.hpp"
#include "features_impl.hpp"
#include "gmm_def.hpp"
#include "gmm_impl.hpp"

inline
multi_action::multi_action(const std::string in_Spath, 
			   const std::string in_Mpath, 
   			   const std::string in_actionNames,  
			   const uword in_col, 
			   const uword in_row,
			   const uvec in_peo_train,
			   const uvec in_peo_test
)
:single_path(in_Spath), multi_path(in_Mpath), actionNames(in_actionNames), col(in_col), row(in_row), peo_train(in_peo_train), peo_test(in_peo_test)
{
  
  actions.load( actionNames );  //actions.print("All actions");
   //Only Run once
  //create_data_list();
  
  
  
}


inline
void
multi_action::features_train()
{
  features calc_feat(single_path, multi_path, actions,  col,row);
  calc_feat.features_per_action_training();
}


inline
void
multi_action::features_multitest()
{
  features calc_feat(single_path, multi_path, actions,  col,row);
 calc_feat.feature_multi_action(); 
}

inline
void
multi_action::train_gmm_model(int NCent)
{
  gmm_model gmm_model(NCent,actions );
  gmm_model.create_gmm_action( );
  
}

inline
void
multi_action::test_gmm_model(int NCent)
{
  gmm_model gmm_model(NCent,actions );
  gmm_model.gmm_multi_action( );
  
}




inline
void
multi_action::create_data_list()
{
  
  uword n_actions   = actions.n_rows;
  int n_scenarios = 4;
  
  
  //Training
  //peo_train 
  //peo_test
  uword np_train = peo_train.n_elem;
  int total_train = np_train*n_actions;
 

  //bool isMissing = false;
  
  
for (uword sc = 1; sc<=4; ++sc  )
{
  cout << "Scenario " << sc << endl;
  field<string> train_list (total_train);
  uvec train_labels(total_train);
  int f = 0;
  for (uword act = 0; act < n_actions; ++act)
  {
    for (uword p_tr=0; p_tr <np_train; ++p_tr)
    {
    
      stringstream tmp_train;
	
	if ( !(peo_train(p_tr)== 13 && act==4 && sc==3)  )
	{
	  if (peo_train(p_tr)<10)
	  {
	    tmp_train << "person0"<< peo_train(p_tr) << "_" << actions(act) << "_d"<< sc << "_uncomp.avi";
	  }
	  else
	  {
	    tmp_train << "person"<< peo_train(p_tr) << "_" << actions(act) << "_d"<< sc << "_uncomp.avi"; 
	    
	  }
	  cout << tmp_train.str() << endl;
	  train_list(f) = tmp_train.str();
	  train_labels(f) = act;
	  ++f;
	}
	else
	{
	  tmp_train << "person"<< peo_train(p_tr) << "_" << actions(act) << "_d"<< sc << "_uncomp.avi"; 
	  cout << tmp_train.str()<< endl;
	  //isMissing=true;
	  cout << "Select another training group. Kill this :) !!!" << endl;
	  getchar();
	}
	
      }
      
    }
    
stringstream save_sc_d;    
save_sc_d << "./run1/train_list_d" << sc << "_Run1.dat";
train_list.save( save_sc_d.str(), raw_ascii);

stringstream save_Labsc_d;    
save_Labsc_d << "./run1/train_label_d"<< sc << "_Run1.dat";
train_labels.save( save_Labsc_d.str() ,raw_ascii);    
}
  

 
  uword np_test = peo_test.n_elem;
  int total_test = np_test*n_scenarios;
  field<string> test_list (total_test); 
  field<string> test_label_list (total_test);

  int f =0;
  
  for (uword p_te = 0; p_te < np_test; ++p_te)
  {
    for (uword sc = 1; sc<=4; ++sc  )
      {
	stringstream tmp_test;
	stringstream tmp_test_lab;
	
	if (peo_test(p_te)<10)
	  {
	    tmp_test << "person0"<< peo_test(p_te) << "_d"<< sc << "_multiactions.avi";
	    tmp_test_lab << "person0"<< peo_test(p_te) << "_d"<< sc << "_MultiLabels.dat";
	  }
	  else
	  {
	    tmp_test << "person"<< peo_test(p_te) << "_d"<< sc << "_multiactions.avi";
	    tmp_test_lab << "person"<< peo_test(p_te) << "_d"<< sc << "_MultiLabels.dat";

	    
	  }
	  test_list(f) = tmp_test.str();
	  test_label_list(f) = tmp_test_lab.str();

	  ++f;

   }
 
}



test_list.save("./run1/test_list_Run1",raw_ascii);
test_label_list.save("./run1/test_list_lab_Run1",raw_ascii);
}